/*
	25AA1024 Driver for the ATmega328p.
	Pin assignments:

	25AA	ATmega328p
	------------------
	~CS	PB2
	SO	PB4
	~WP	+5V
	~HOLD	+5V
	SCK	PB5
	SI	PB3

	This driver utilizes the following hardware capabilities of the
	ATmega328p:
		SPI
*/

#include <avr/io.h>
#include "../comm/communication.h"

#ifndef F_CPU
#define F_CPU 20000000
#endif

#include <util/delay.h>

#ifndef _25AA1024_H_
#define _25AA1024_H_

//Pin assignments
#define _CS	PB2
#define _SO	PB4
#define _WP	PB1
#define _HOLD	PD0
#define _SCK	PB5
#define _SI	PB3

//Instruction set
#define _READ	0x03
#define _WRITE	0x02
#define _WREN	0x06
#define _WRDI	0x04
#define _RDSR	0x05
#define _WRSR	0x01
#define _PE	0x42
#define _SE	0xD8
#define _CE	0xC7
#define _RDID	0xAB
#define _DPD	0xB9

//Bit masks for status register
#define _WIP	0x01
#define _WEL	0x02
#define _BP0	0x04
#define _BP1	0x08
#define _WR	0x80

//Functions

void read(uint8_t *address, int amount, uint8_t *data);
void write(uint8_t *data, uint8_t amount, uint8_t *address);

#endif
